/* PRESET CODE BEGIN - NEVER TOUCH CODE BELOW */  
 
#include "stdio.h"  
#include "stdlib.h"  
  
struct node  
{   int data;  
    struct node * next;  
} ;  
  
typedef struct node NODE;  
typedef struct node * PNODE;  
void outlist( PNODE );  
void sortlist( PNODE , int );  
  
int main ( )  
{   int num=1;  
    PNODE head;  
  
    head = (PNODE)malloc( sizeof(NODE) );  
    head->next = NULL;  
    head->data = -1;  
  
    while ( num!=0 )  
    {   
		scanf("%d", &num);  
        if ( num!=0 )  
            sortlist( head, num);  
    }  
    outlist( head );  
    return 0;  
}  
  
void outlist( PNODE head )  
{   
	PNODE p;  
    p = head->next;  
    while ( p != NULL )  
    {   printf("%d\n", p->data);  
        p = p->next;  
    }  
}  
  

void sortlist( PNODE h, int num ) 
{   
	PNODE pre=h;
	PNODE cur=h->next;
	PNODE add;
	
	while( cur != NULL && cur->data < num )
	{
		pre = cur;
		cur = cur->next;
	}
	
	if ( cur == NULL )	//说明这是最大的一个数，到最后进行存储
	{
		cur = ( PNODE )malloc( sizeof(NODE) );
		cur->data = num;
		cur->next = NULL;
		pre->next = cur;
	}
	else
	{
		if ( num == cur->data )
		{
			return;
		}
		else if( num < cur->data)
		{
			add = ( PNODE )malloc( sizeof(NODE) );
			add->data = num;
			pre->next = add;
			add->next = cur;
		}
	}
} 

  
